package com.appspot.moviesessions.interfaces.webapp.dto;

import java.util.Date;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

import org.apache.commons.lang.builder.ToStringBuilder;

@XmlRootElement(name = "session")
public class Session {

	@XmlAttribute
	private Long movie;

	@XmlAttribute
	private Date time;

	@XmlAttribute
	private Long location;

	public static Session fromSession(
			com.appspot.moviesessions.model.Session session) {
		Session dto = new Session();
		dto.movie = session.getMovie().getId();
		dto.time = session.getTime();
		dto.location = session.getLocation().getId();
		return dto;
	}

	public Long getMovie() {
		return movie;
	}

	public Date getTime() {
		return time;
	}

	@XmlAttribute
	public Long getEpochTime() {
		// time in seconds
		return time.getTime();
	}

	public Long getLocation() {
		return location;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}
}
